home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / bin / applet-coherence < prev    next >
Text File  |  2009-10-09  |  3KB  |  103 lines

  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. # Applet for Coherence
  4. # Copyright (C) 2008 Nicolas L├⌐cureuil <neoclust@mandriva.org>
  5. # Copyright (C) 2008 Helio Chissini de Castro <helio@mandriva.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2, or (at your option)
  10. # any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. #
  21. # TODO : Add a configuration windows to allow to change name or plugins before launching
  22. #        the server and save a configuration file in ~/.coherence
  23. #        Use the name and the plugin   given as commandline arguments
  24. #
  25.  
  26. import time
  27. import os
  28. import subprocess
  29. import signal
  30. import sys
  31. import socket
  32.  
  33. from pkg_resources import resource_filename
  34. icon = resource_filename(__name__, '../../misc/Desktop Applet/tango-system-file-manager.png')
  35. # this ../.. is evil, I know :-(
  36. # there must be a better way
  37. if not os.path.exists(icon):
  38.     icon = "/usr/share/icons/coherence/tango-system-file-manager.png"
  39.  
  40. from PyQt4.QtGui import *
  41. from PyQt4.QtCore import *
  42. from PyQt4 import QtCore
  43.  
  44.  
  45. proc = None
  46. host = None
  47. user = None
  48. confFile = None
  49. bool = False
  50.  
  51. def startCoherence():
  52.     global proc
  53.     global host
  54.     global user
  55.     global confFile
  56.     global bool
  57.     host = socket.gethostname()
  58.     user = os.environ["USER"]
  59.     if ( confFile ):
  60.         if os.path.isfile( confFile ):
  61.             proc = subprocess.Popen(["/usr/bin/coherence"])
  62.     else:
  63.         proc = subprocess.Popen(["/usr/bin/coherence","--plugin=backend:FSStore,name:%s@%s" % ( user, host )])
  64.     startAction.setDisabled(1)
  65.     stopAction.setDisabled(0)
  66.     bool = True
  67.  
  68. def stopCoherence():
  69.     global bool
  70.     os.kill( proc.pid, signal.SIGTERM )
  71.     stopAction.setDisabled(1)
  72.     startAction.setDisabled(0)
  73.     bool = False
  74.  
  75. def quitApplet():
  76.     if bool == True:
  77.         stopCoherence()
  78.  
  79. if __name__ == "__main__":
  80.     app = QApplication(sys.argv)
  81.  
  82.  
  83.     menu = QMenu()
  84.     startAction = menu.addAction('Start Coherence Server')
  85.     stopAction = menu.addAction('Stop Coherence Server')
  86.     quitAction = menu.addAction('Quit')
  87.  
  88.     systrayIcon = QString(icon)
  89.     icon = QIcon(systrayIcon)
  90.     quitAction.connect( quitAction, SIGNAL("triggered()"), quitApplet)
  91.     quitAction.connect( quitAction, SIGNAL("triggered()"), app, QtCore.SLOT("quit()"))
  92.     startAction.connect( startAction, SIGNAL("triggered()"), startCoherence)
  93.     stopAction.connect( stopAction, SIGNAL("triggered()"), stopCoherence)
  94.     stopAction.setDisabled(1)
  95.  
  96.     tray = QSystemTrayIcon(icon)
  97.     if (tray.isSystemTrayAvailable()):
  98.         tray.setContextMenu(menu)
  99.         tray.show()
  100.         tray.setToolTip("Coherence control Applet")
  101.  
  102.     sys.exit(app.exec_())
  103.